<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import screenfull from 'screenfull'
import { useMessage } from '@/hooks/web/useMessage'

// 是否全屏
const isFullscreen = ref(false)

const handleFullscreen = () => {
  if (!screenfull.isEnabled) useMessage().warning({ message: '当前您的浏览器不支持全屏 ❌' })
  screenfull.toggle()
}

onMounted(() => {
  screenfull.on('change', () => {
    if (screenfull.isFullscreen) isFullscreen.value = true
    else isFullscreen.value = false
  })
})
</script>

<template>
  <div class="fullscreen" @click="handleFullscreen">
    <SvgIcon :icon="isFullscreen ? 'close-fullscreen' : 'fullscreen'" />
  </div>
</template>

<style lang="scss" scoped>
.svg-icon {
  color: var(--el-header-text-color);
}
</style>
